

<template>
  <div>
    <el-row>
      <el-col :span="12">
        <div id="main" style="width: 500px; height: 400px"></div>
      </el-col>

      <el-col :span="12">
        <div id="pie" style="width: 500px; height: 400px"></div>
      </el-col>

    </el-row>



  </div>

</template>

<script>
import * as echarts from 'echarts';

export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: "Echarts",
  data(){
    return {

    }
  },
  mounted() {  //页面元素渲染完才执行
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    var option = {
      title: {
        text: '各个季度的购买量',
        subtext: '趋势图',
        left: 'center'
      },
      xAxis: {
        type: 'category',
        data: ['春','夏','秋','冬']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [],
          type: 'line'
        }
      ]
    };

    this.request.get("/echarts/numbers").then(res =>{

      option.series[0].data = res.data
      myChart.setOption(option);

    })



    var chartDomPie = document.getElementById('pie');
    var myChartPie = echarts.init(chartDomPie);
    var optionPie = {
      title: {
        text: '图书存储量',
        subtext: '类别',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: '50%',
          data: [
            { value: 1048, name: '教育' },
            { value: 735, name: '人文' },
            { value: 580, name: '历史' },
            { value: 484, name: '散文' },
            { value: 300, name: '小说' }
          ],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };
    myChartPie.setOption(optionPie)




  }
}
</script>

<style scoped>

</style>
